import request from "@/api/CategorySelector"
const state = {
    Category1List:[],
    Category2List:[],
    Category3List:[],
}

const mutations = {
    CATEGORY_1LIST(state,cate1){
        state.Category1List = cate1
    },
    CATEGORY_2LIST(state,cate2){
        state.Category2List = cate2
    },
    CATEGORY_3LIST(state,cate3){
        state.Category3List = cate3
    }
}

const actions = {
    async Category1Actions({state,commit}){
        state.Category2List = []
        state.Category3List = []
        try {
            let result = await request.getCategory1()
            commit('CATEGORY_1LIST',result.data)
        } catch (error) {
            console.log("一级分类获取失败");
        }
    },
    async Category2Actions({commit},idx){
        state.Category3List = []
        try {
            let result = await request.getCategory2(idx)
            commit('CATEGORY_2LIST',result.data)
        } catch (error) {
            console.log('二级分类获取失败');
        }
    },
    async Category3Actions({commit},idx){
        try {
            let result = await request.getCategory3(idx)
            commit('CATEGORY_3LIST',result.data)
        } catch (error) {
            console.log('三级分类获取失败');
        }
    },
}

const getters = {}

export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters
}
